"""
HumanBreakerInputFrame.py

Created by Zach Epolito on 09/24/2008.
"""

import sys
import string
import os
from Tkinter import *

class HumanBreakerInputFrame(Frame):
    """class that allows the user to input the breaker move.
       this frame is inserted into the InputView and performs a callback
       when the input is collected
    """

    responseButs = [Button(),Button(),Button(),Button()]
    colorIndex = ["red","blue","yellow","green","white","black"]
    
    def __init__(self,master,doneHandler,**kv):
        """constructor. doneHandler is the callback function to be called
           when the input is collected
        """
        Frame.__init__(self,master,kv)
        self.responseVals = [0,0,0,0]
        self.doneHandler = doneHandler

        self.responseButs[0] = Button(self, command=self.changeButtonZero, bg=self.colorIndex[0])
        self.responseButs[0].config(height=2, width=2, bd = 10)
        self.responseButs[1] = Button(self, command=self.changeButtonOne, bg=self.colorIndex[0])
        self.responseButs[1].config(height=2, width=2, bd = 10)
        self.responseButs[2] = Button(self, command=self.changeButtonTwo, bg=self.colorIndex[0])
        self.responseButs[2].config(height=2, width=2, bd = 10)
        self.responseButs[3] = Button(self, command=self.changeButtonThree, bg=self.colorIndex[0])
        self.responseButs[3].config(height=2, width=2, bd = 10)

        self.doneButton = Button(self, text="Done", command=self.handleDone)
        self.doneButton.config(height=2, width=12)

        self.responseButs[0].grid(row=0, column=0)
        self.responseButs[1].grid(row=0, column=1)
        self.responseButs[2].grid(row=0, column=2)
        self.responseButs[3].grid(row=0, column=3)
        self.doneButton.grid(row=0, column=4)

    def changeButtonZero(self):
        """changes the color of the first button"""
        self.responseVals[0] = self.responseVals[0] + 1
        self.responseVals[0] = self.responseVals[0] % 6
        self.responseButs[0].config (bg=self.colorIndex[self.responseVals[0]])
        #self.responseButs[0].config (text=self.responseVals[0])

    def changeButtonOne(self):
        """changes the color of the second button"""
        self.responseVals[1] = self.responseVals[1] + 1
        self.responseVals[1] = self.responseVals[1] % 6
        self.responseButs[1].config (bg=self.colorIndex[self.responseVals[1]])
        #self.responseButs[1].config (text=self.responseVals[1])

    def changeButtonTwo(self):
        """changes the color of the third button"""
        self.responseVals[2] = self.responseVals[2] + 1
        self.responseVals[2] = self.responseVals[2] % 6
        self.responseButs[2].config (bg=self.colorIndex[self.responseVals[2]])
        #self.responseButs[2].config (text=self.responseVals[2])

    def changeButtonThree(self):
        """changes the color of the forth button"""
        self.responseVals[3] = self.responseVals[3] + 1
        self.responseVals[3] = self.responseVals[3] % 6
        self.responseButs[3].config (bg=self.colorIndex[self.responseVals[3]])
        #self.responseButs[3].config (text=self.responseVals[3])

    def handleDone(self):
        """callback"""
        self.doneHandler(self.responseVals)

    def reset(self):
        """reset the buttons"""
        self.responseVals = [0,0,0,0]
        self.responseButs[0].config (text=self.responseVals[0])
        self.responseButs[1].config (text=self.responseVals[1])
        self.responseButs[2].config (text=self.responseVals[2])
        self.responseButs[3].config (text=self.responseVals[3])
